<template>
  <div class="content">
    <div>
      <h3>产品编码表</h3>
    </div>
    <!--v-on:click="deldetailsData()"-->
    <el-button type="danger" @click="dialogVisible = true" v-on:click="deldetailsData()">新增产品编码</el-button>
    <el-button type="primary">删除</el-button>
    <el-input v-model="search" placeholder="请输入商品编码关键字搜索" class="input"></el-input>
    <el-button type="primary" @click="query">查询更多</el-button>
    <div style="background-color: white;margin-top: 10px" v-if="chaxun">
      <table>
        <tr>
          <td>
            <el-select v-model="productTypeList_value" style="width: 200px" placeholder="商品类型">
              <el-option
                v-for="item in productTypeList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </td>
          <td>
            <el-select v-model="styleList_value" style="width: 200px" placeholder="款式">
              <el-option
                v-for="item in styleList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </td>
          <td>
            <el-select v-model="productSetList_value" style="width: 200px" placeholder="系列">
              <el-option
                v-for="item in productSetList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </td>
          <td>
            <el-button type="success" @click="queryList">搜索</el-button>
            <el-button type="success" @click="getData">查询全部</el-button>
            <el-button type="success" @click="shou">收起</el-button>
          </td>
          <td>
          </td>
        </tr>
      </table>
    </div>
    <el-table :data="tables(search)" style="width: 100%">
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column prop="id" label="序号" type="index"></el-table-column>
      <el-table-column prop="productType.ptname" label="商品类型"></el-table-column>
      <el-table-column prop="pcode" label="商品编码"></el-table-column>
      <el-table-column prop="pname" label="商品名称"></el-table-column>
      <el-table-column prop="pmould_no" label="模具号"></el-table-column>
      <el-table-column prop="supplier.sname" label="供应商"></el-table-column>
      <el-table-column prop="psection_number" label="款号"></el-table-column>
      <el-table-column prop="pecommerce_fund_no" label="电商款号"></el-table-column>
      <el-table-column prop="more" label="更多">
          <template scope="scope">
            <el-button class="btn" size="small" @click="substitution = true" v-on:click="viewdetails(scope.$index, scope.row)">详情</el-button>
            <el-button class="btn" size="small" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
          </template>
      </el-table-column>
    </el-table>
    <!--新增模态框-->
    <el-dialog title="新增产品编码" :visible.sync="dialogVisible" width="60%" :before-close="handleClose">
      <table class="Product_coding_table">
        <tr>
          <td>商品类型：</td>
          <td>
            <!--<input type="text" v-model="productTypeList.ptname">-->
            <el-select v-model="productTypeList_value" placeholder="素金类" >
              <el-option  v-for="item in productTypeList" :label="item.value" :value="item.label">
              </el-option>
            </el-select>
          </td>
          <td>商品编码：</td>
          <td>
            <input type="text" v-model="addData.pcode">
          </td>
          <td>商品名称：</td>
          <td colspan="3">
            <input type="text" v-model="addData.pname">
          </td>
        </tr>
        <tr>
          <td>模具号：</td>
          <td>
            <input type="text" v-model="addData.pmould_no">
          </td>
          <td>供应商：</td>
          <td>
            <!--<input type="text" v-model="detailsData.supplier">-->
            <el-select v-model="supplierList_value" placeholder="供应商" >
              <el-option  v-for="item in supplierList" :label="item.value" :value="item.label">
              </el-option>
            </el-select>
          </td>
          <td>款号：</td>
          <td>
            <input type="text" v-model="addData.psection_number">
          </td>
          <td>电商款号：</td>
          <td>
            <input type="text" v-model="addData.pecommerce_fund_no">
          </td>
        </tr>
        <tr>
          <td>成色：</td>
          <td>
            <el-select v-model="conditionList_value" placeholder="成色">
              <el-option v-for="item in conditionList" :label="item.value" :value="item.label"></el-option>
            </el-select>
          </td>
          <td>石料：</td>
          <td>
            <!--<input type="text" v-model="detailsData.stone_material">-->
            <el-select v-model="paggregatedRockList_value" placeholder="石料">
              <el-option v-for="item in paggregatedRockList" :label="item.value" :value="item.label"></el-option>
            </el-select>
          </td>
          <td>属性：</td>
          <td>
            <!--<input type="text" v-model="detailsData.attribute">-->
            <el-select v-model="propertyList_value" placeholder="属性">
              <el-option v-for="item in propertyList" :label="item.value" :value="item.label"></el-option>
            </el-select>
          </td>
          <td>款式：</td>
          <td>
            <!--<input type="text" v-model="detailsData.style">-->
            <el-select v-model="styleList_value" placeholder="款式">
              <el-option v-for="item in styleList" :label="item.value" :value="item.label"></el-option>
            </el-select>
          </td>
        </tr>
        <tr>
          <td>参考重量：</td>
          <td>
            <input type="text" v-model="addData.pconsult_weight">
          </td>
          <td>重量单位</td>
          <td>
            <el-select v-model="weightUnitList_value" placeholder="重量单位">
              <el-option v-for="item in weightUnitList" :label="item.value" :value="item.label"></el-option>
            </el-select>
          </td>
          <td>手寸：</td>
          <td>
            <input type="text" v-model="addData.product_hand">
          </td>
          <td>商品分类</td>
          <td>
            <el-select v-model="productClassifyList_value" placeholder="商品分类">
              <el-option v-for="item in productClassifyList" :label="item.value" :value="item.label"></el-option>
            </el-select>
          </td>
        </tr>
        <tr>
          <td>成本计价：</td>
          <td>
            <input type="text" v-model="addData.pprime_cost_valuation">
          </td>
          <td>成本价：</td>
          <td>
            <input type="text" v-model="addData.pprime_cost_price">
          </td>
          <td>市场价：</td>
          <td>
            <input type="text" v-model="addData.pmarket_house_price">
          </td>
          <td>标签单价：</td>
          <td>
            <input type="text" v-model="addData.plabel_price">
          </td>
        </tr>
        <tr>
          <td>销售计价：</td>
          <td>
            <!--<input type="text" v-model="detailsData.sales_valuation">-->
            <el-select v-model="weightList.value" placeholder="重量">
              <el-option v-for="item in weightList" :label="item.value" :value="item.label"></el-option>
            </el-select>
          </td>
          <!--<td>销售工费计价：</td>-->
          <!--<td>-->
            <!--&lt;!&ndash;<input type="text" v-model="detailsData.sales_work_cost_valuation">&ndash;&gt;-->
            <!--<el-select v-model="weightList.value" placeholder="重量">-->
              <!--<el-option v-for="item in weightList" :label="item.value" :value="item.label"></el-option>-->
            <!--</el-select>-->
          <!--</td>-->
          <td>销售工费：</td>
          <td>
            <input type="text" v-model="addData.psales_cost">
          </td>
          <td>销售附加费：</td>
          <td>
            <input type="text" v-model="addData.psell_extra_charge">
          </td>
        </tr>
        <tr>
          <td>库存计量：</td>
          <td colspan="2">
            <el-radio v-model="radio" @change="aradio" label="是">计算</el-radio>
            <el-radio v-model="radio" @change="aradio" label="否">不计算</el-radio>
          </td>
          <td>含金量</td>
          <td>
            <el-select v-model="goldContentList_value" placeholder="含金量">
              <el-option v-for="item in goldContentList" :label="item.value" :value="item.label"></el-option>
            </el-select>
          </td>
          <td>系列</td>
          <td>
            <el-select v-model="productSetList_value" placeholder="系列">
              <el-option v-for="item in productSetList" :label="item.value" :value="item.label"></el-option>
            </el-select>
          </td>
        </tr>
        <tr>
          <td>提成分类：</td>
          <td>
            <input type="text" v-model="addData.ppush_money">
          </td>
          <td>分类1：</td>
          <td>
            <!--<input type="text" v-model="detailsData.classification1">-->
            <el-select v-model="pushMoneyList_value" placeholder="分类1">
              <el-option  v-for="item in pushMoneyList" :label="item.value" :value="item.label">
              </el-option>
            </el-select>
          </td>
          <td>分类2：</td>
          <td>
            <el-select v-model="pushMoneyList_value" placeholder="分类2">
              <el-option  v-for="item in pushMoneyList" :label="item.value" :value="item.label">
              </el-option>
            </el-select>
          </td>
        </tr>
      </table>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="dialogVisible = false" v-on:click="add" >确 定</el-button>
  </span>
    </el-dialog>
    <!--查看详情模态框 :visible.sync="substitution" class="details_table"-->
    <el-dialog title="商品详情" :visible.sync="substitution" width="60%" :before-close="handleClose">
      <table class="details_table">
        <tr>
          <td>商品类型：</td>
          <td>
            <!--<input type="text" v-model="productTypeList.ptname">-->
            <el-select v-model="productTypeList_value" placeholder="素金类" >
              <el-option  v-for="item in productTypeList" :label="item.value" :value="item.label">
              </el-option>
            </el-select>
          </td>
          <td>商品编码：</td>
          <td>
            <input type="text" v-model="detailsData.pcode">
          </td>
          <td>商品名称：</td>
          <td colspan="3">
            <input type="text" v-model="detailsData.pname">
          </td>
        </tr>
        <tr>
          <td>模具号：</td>
          <td>
            <input type="text" v-model="detailsData.pmould_no">
          </td>
          <td>供应商：</td>
          <td>
            <!--<input type="text" v-model="detailsData.supplier">-->
            <el-select v-model="supplierList_value" placeholder="供应商" >
              <el-option  v-for="item in supplierList" :label="item.value" :value="item.label">
              </el-option>
            </el-select>
          </td>
          <td>款号：</td>
          <td>
            <input type="text" v-model="detailsData.psection_number">
          </td>
          <td>电商款号：</td>
          <td>
            <input type="text" v-model="detailsData.pecommerce_fund_no">
          </td>
        </tr>
        <tr>
          <td>成色：</td>
          <td>
            <el-select v-model="conditionList_value" placeholder="成色">
              <el-option v-for="item in conditionList" :label="item.value" :value="item.label"></el-option>
            </el-select>
          </td>
          <td>石料：</td>
          <td>
            <!--<input type="text" v-model="detailsData.stone_material">-->
            <el-select v-model="paggregatedRockList_value" placeholder="石料">
              <el-option v-for="item in paggregatedRockList" :label="item.value" :value="item.label"></el-option>
            </el-select>
          </td>
          <td>属性：</td>
          <td>
            <!--<input type="text" v-model="detailsData.attribute">-->
            <el-select v-model="propertyList_value" placeholder="属性">
              <el-option v-for="item in propertyList" :label="item.value" :value="item.label"></el-option>
            </el-select>
          </td>
          <td>款式：</td>
          <td>
            <!--<input type="text" v-model="detailsData.style">-->
            <el-select v-model="styleList_value" placeholder="款式">
              <el-option v-for="item in styleList" :label="item.value" :value="item.label"></el-option>
            </el-select>
          </td>
        </tr>
        <tr>
          <td>参考重量：</td>
          <td>
            <input type="text" v-model="detailsData.pconsult_weight">
          </td>
          <td>重量单位</td>
          <td>
            <el-select v-model="weightUnitList_value" placeholder="重量单位">
              <el-option v-for="item in weightUnitList" :label="item.value" :value="item.label"></el-option>
            </el-select>
          </td>
          <td>手寸：</td>
          <td>
            <input type="text" v-model="detailsData.product_hand">
          </td>
          <td>商品分类</td>
          <td>
            <el-select v-model="productClassifyList_value" placeholder="商品分类">
              <el-option v-for="item in productClassifyList" :label="item.value" :value="item.label"></el-option>
            </el-select>
          </td>
        </tr>
        <tr>
          <td>成本计价：</td>
          <td>
            <!--<input type="text" v-model="detailsData.cost_valuation">-->
            <el-select v-model="weightList.value" placeholder="重量">
              <el-option v-for="item in weightList" :label="item.value" :value="item.label"></el-option>
            </el-select>
          </td>
          <td>成本价：</td>
          <td>
            <input type="text" v-model="detailsData.pprime_cost_price">
          </td>
          <td>市场价：</td>
          <td>
            <input type="text" v-model="detailsData.pmarket_house_price">
          </td>
          <td>标签单价：</td>
          <td>
            <input type="text" v-model="detailsData.plabel_price">
          </td>
        </tr>
        <tr>
          <td>销售计价：</td>
          <td>
            <!--<input type="text" v-model="detailsData.sales_valuation">-->
            <el-select v-model="weightList.value" placeholder="重量">
              <el-option v-for="item in weightList" :label="item.value" :value="item.label"></el-option>
            </el-select>
          </td>
          <td>销售工费：</td>
          <td>
            <input type="text" v-model="detailsData.psales_cost">
          </td>
          <td>销售附加费：</td>
          <td>
            <input type="text" v-model="detailsData.psell_extra_charge">
          </td>
        </tr>
        <tr>
          <td>库存计量：</td>
          <td colspan="2">
            <el-radio v-model="radio" @change="aradio" label="是">计算</el-radio>
            <el-radio v-model="radio" @change="aradio" label="否">不计算</el-radio>
          </td>
          <td>含金量</td>
          <td>
            <el-select v-model="goldContentList_value" placeholder="含金量">
              <el-option v-for="item in goldContentList" :label="item.value" :value="item.label"></el-option>
            </el-select>
          </td>
          <td>系列</td>
          <td>
            <el-select v-model="productSetList_value" placeholder="系列">
              <el-option v-for="item in productSetList" :label="item.value" :value="item.label"></el-option>
            </el-select>
          </td>
        </tr>
        <tr>
          <td>提成分类：</td>
          <td>
            <input type="text" v-model="detailsData.ppush_money">
          </td>
          <td>分类1：</td>
          <td>
            <!--<input type="text" v-model="detailsData.classification1">-->
            <el-select v-model="pushMoneyList_value" placeholder="分类1">
              <el-option  v-for="item in pushMoneyList" :label="item.value" :value="item.label">
              </el-option>
            </el-select>
          </td>
          <td>分类2：</td>
          <td>
            <el-select v-model="pushMoneyList_value" placeholder="分类2">
              <el-option  v-for="item in pushMoneyList" :label="item.value" :value="item.label">
              </el-option>
            </el-select>
          </td>
        </tr>
      </table>
      <span slot="footer" class="dialog-footer">
          <el-button @click="substitution = false">取 消</el-button>
          <el-button type="primary" @click="substitution = false" v-on:click="edit()">修改</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>
  // import qs from 'qs'
  export default {
    name: "product_code_list",
    data(){
      return {
        chaxun:false,
        radio: '1',
        dialogVisible: false,
        substitution:false,
        search:"",
        value:"",
        productTypeList_value:"",
        supplierList_value:"",
        conditionList_value:"",
        paggregatedRockList_value:"",
        propertyList_value:"",
        styleList_value:"",
        pushMoneyList_value:"",
        productClassifyList_value:"",
        productSetList_value:"",
        weightUnitList_value:"",
        goldContentList_value:"",
        //成本计价、销售计价、销售工费计价
        weightList:[
          {
            value:"重量",
            label:"重量"
          },
          {
            value:"数量",
            label:"数量"
          },
        ],
        //商品类型列表
        productTypeList:[],
        // 运营商列表
        supplierList:[],
        //成色列表
        conditionList:[],
        //石料列表
        paggregatedRockList:[],
        // 属性列表
        propertyList:[],
        // 款式列表
        styleList:[],
        // 分类列表
        pushMoneyList:[],
        //商品分类
        productClassifyList:[],
        //下拉列表数组
        totalList:[],
        //系列
        productSetList:[],
        //重量单位
        weightUnitList:[],
        //含金量
        goldContentList:[],

        detailsData:{
          pid:'',//自增id
          productType: '',//商品类型
          pcode:'',//商品编码
          pname:'',//商品名
          pmould_no:'',//模具号
          supplier:'',//供应商
          psection_number:'',//款号
          pecommerce_fund_no:'',//电商款号
          productClassify:"",//商品分类
          condition:'',//成色
          paggregatedRock:'',//石料
          property:'',//属性
          style:'',//款式
          pconsult_weight:'',//参考重量
          weightUnit:"",//重量单位
          product_hand:'',//手寸
          goldContent:"",//含金量
          pprime_cost_valuation:'',//成本计价
          pprime_cost_price:'',//成本价
          pmarket_house_price:'',//市场价
          psell_valuation:'',//销售计价
          plabel_price:'',//标签单价
          psales_cost:'',//销售工费
          psell_extra_charge:'',//销售附加费
          pstock_count:'',//是否纳入库存，计算库存
          ppush_money:'',//提成分类
          ppush_money1:'',//分类1
          ppush_money2:'',//分类2
          productSet:"",//系列
        },
        addData:{
          productType: '',//商品类型
          pcode:'',//商品编码
          pname:'',//商品名
          pmould_no:'',//模具号
          supplier:'',//供应商
          psection_number:'',//款号
          pecommerce_fund_no:'',//电商款号
          productClassify:"",//商品分类
          condition:'',//成色
          paggregatedRock:'',//石料
          property:'',//属性
          style:'',//款式
          pconsult_weight:'',//参考重量
          weightUnit:"",//重量单位
          product_hand:'',//手寸
          goldContent:"",//含金量
          pprime_cost_valuation:'',//成本计价
          pprime_cost_price:'',//成本价
          pmarket_house_price:'',//市场价
          psell_valuation:'',//销售计价
          plabel_price:'',//标签单价
          psales_cost:'',//销售工费
          psell_extra_charge:'',//销售附加费
          pstock_count:'',//是否纳入库存，计算库存
          ppush_money:'',//提成分类
          ppush_money1:'',//分类1
          ppush_money2:'',//分类2
          productSet:"",//系列
        },
        tableData: [],
        methods: {
          handleClose(done) {
            this.$confirm('确认关闭？')
              .then(_ => {
                done();
              })
              .catch(_ => {});
          },
        },
      }
    },
    created(){
      this.getData();
      this.getselct();
    },
    methods:{
      // //下拉选中
      // productTypeListSelect(value) {
      //   let obj = {};
      //   obj = this.productTypeList.find((item) => {
      //     return item.value=== value
      //   });
      //   console.log(obj.value)
      // },
      //给查询框加初始化选择
      queryList(){
        let ptid,sid,psid;
        //商品类型
        for (let i = 0;i<this.totalList.productTypeList.length;i++){
          if(this.totalList.productTypeList[i].ptname ===this.productTypeList_value){
            this.detailsData.productType = this.totalList.productTypeList[i];
            break;
          }
        }
        //款式
        for (let i = 0;i<this.totalList.styleList.length;i++){
          if(this.totalList.styleList[i].sname ===this.styleList_value){
            this.detailsData.style = this.totalList.styleList[i];
            break;
          }
        }
        // 系列
        for (let i = 0;i<this.totalList.productSetList.length;i++){
          if(this.totalList.productSetList[i].psname ===this.productSetList_value){
            this.detailsData.productSet = this.totalList.productSetList[i];
            break;
          }
        }
        if (this.detailsData.productType.ptid !=undefined){
          ptid =this.detailsData.productType.ptid;
        }else {
          ptid=""
        }
        if (this.detailsData.style.sid !=undefined){
          sid =this.detailsData.style.sid
        }else {
          sid=""
        }
        if (this.detailsData.productSet.psid !=undefined){
          psid =this.detailsData.productSet.psid
        }else {
          psid=""
        }
        let data={
          pproduct_type_ptid:ptid,//商品类型
          pstyle_sid:sid,//款式
          product_product_set_psid:psid,//系列
        };
        this.$axios.post("http://172.16.6.73:8080/product/selectByCondition.action",data , {
            transformRequest: [
              function (data) {
                let params = "";
                var arr = [];
                for (var key in data) {
                  arr.push(key + "=" + data[key]);
                }
                params = arr.join("&");
                return params;
              }
            ]
          },
          {
            headers: {
              'Content-Type': 'application/x-www-form-urlencoded'
            }
          }).then((res) => {
          console.log("查询成功");
          this.tableData=res.data.data.data;
          console.log(res)
          this.deldetailsData();
          // this.getData();
        });
      },
      //打开查询
      query(){
        if(this.chaxun!=true){
          this.chaxun =true
        }else {
          this.chaxun = false
        }
      },
      //收起查询
      shou(){
        this.chaxun=false
      },
      //获取单选
      aradio(){
        console.log("选中"+this.radio)    //要写的方法,
      },
      //下拉列表改变
      changeValue(value) {
        console.log(value);
        let obj = {};
        obj = this.productTypeList.find((item)=>{
          return item.value === value;
        });
        console.log(obj.label);
      },
      //这是关闭模态框
      handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done();
          })
          .catch(_ => {});
      },
      // //获取json数据
      // getData() {
      //   this.$axios.get("../static/Product_coding.json").then(response => {
      //     this.tableData = response.data.first;
      //   });
      // },
//获取后台数据的
      getData(){
        this.$axios.get("http://172.16.6.73:8080/product/selectProduct.action").then(
          (res) => {
          // console.log(res.data.data[0]);
          // for (var i=0;i<response.data.data.length;i++){
          //   this.tableData.push(response.data.data[i])
          // }
            console.log(res.data);
            this.tableData = res.data.data.data;
            this.deldetailsData()
        });
      },
      //获取后台下拉列表框
      getselct(){
        this.$axios.post("http://172.16.6.73:8080/product/spinner.action").then(
          (res) => {
            console.log("列表")
            console.log(res.data);
            this.totalList = res.data;
            // 获取商品类型
            for(let i=0;i<res.data.productTypeList.length;i++){
              let obj;
              obj={
                value:res.data.productTypeList[i].ptname,
                label:res.data.productTypeList[i].ptname
              };
              this.productTypeList.push(obj);
            }
            //获取供应商
            for(let i=0;i<res.data.supplierList.length;i++){
              var obj
              obj={
                value:res.data.supplierList[i].sname,
                label:res.data.supplierList[i].sname
              };
              this.supplierList.push(obj);
            }
            //获取成色
            for(let i=0;i<res.data.conditionList.length;i++){
              var obj
              obj={
                value:res.data.conditionList[i].cname,
                label:res.data.conditionList[i].cname
              };
              this.conditionList.push(obj);
            }
            //石料
            for(let i=0;i<res.data.paggregatedRockList.length;i++){
              var obj
              obj={
                value:res.data.paggregatedRockList[i].paggregated_rock_name,
                label:res.data.paggregatedRockList[i].paggregated_rock_name
              };
              this.paggregatedRockList.push(obj);
            }
            //属性
            for(let i=0;i<res.data.propertyList.length;i++){
              var obj
              obj={
                value:res.data.propertyList[i].pname,
                label:res.data.propertyList[i].pname
              };
              this.propertyList.push(obj);
            }
            //款式
            for(let i=0;i<res.data.styleList.length;i++){
              var obj
              obj={
                value:res.data.styleList[i].sname,
                label:res.data.styleList[i].sname
              };
              this.styleList.push(obj);
            }
            //分类
            for(let i=0;i<res.data.pushMoneyList.length;i++){
              var obj
              obj={
                value:res.data.pushMoneyList[i].pmname,
                label:res.data.pushMoneyList[i].pmname
              };
              this.pushMoneyList.push(obj);
            }
            //商品分类
            for(let i=0;i<res.data.productClassifyList.length;i++){
              var obj
              obj={
                value:res.data.productClassifyList[i].pccategory_one,
                label:res.data.productClassifyList[i].pccategory_one
              };
              this.productClassifyList.push(obj);
            }
            //系列
            for(let i=0;i<res.data.productSetList.length;i++){
              var obj
              obj={
                value:res.data.productSetList[i].psname,
                label:res.data.productSetList[i].psname
              };
              this.productSetList.push(obj);
            }
            //重量单位weightUnitList_value
            for(let i=0;i<res.data.weightUnitList.length;i++){
              var obj
              obj={
                value:res.data.weightUnitList[i].wuname,
                label:res.data.weightUnitList[i].wuname
              };
              this.weightUnitList.push(obj);
            }
            //含金量goldContentList_value
            for(let i=0;i<res.data.goldContentList.length;i++){
              var obj
              obj={
                value:res.data.goldContentList[i].gcname,
                label:res.data.goldContentList[i].gcname
              };
              this.goldContentList.push(obj);
            }
          });
      },
      //清空detailsData数据
      deldetailsData(){
        let obj = this.addData;
        for(let key in obj){
          obj[key]  = ''
        }
        this.productTypeList_value="";
        this.supplierList_value="";
        this.conditionList_value="";
        this.paggregatedRockList_value="";
        this.propertyList_value="";
        this.styleList_value="";
        this.pushMoneyList_value="";
        this.productClassifyList_value="";
        this.productSetList_value="";
        this.weightUnitList_value="";
        this.goldContentList_value="";
        this.weightUnitList_value="";
        console.log(3333333333333);
      },
      // 这是查看详情
      viewdetails(index){
        // console.log("222222222222222222");
        console.log(this.tableData[index].pid);
        if(this.tableData[index].productType.ptname == ""){
          this.productTypeList_value = ""
        }else
          {
          this.productTypeList_value = this.tableData[index].productType.ptname;//商品类型
        }
        if(this.tableData[index].supplier.sname == ""){
          this.supplierList_value = ''
        }else {
          this.supplierList_value = this.tableData[index].supplier.sname;//供应商
        }
        if(this.tableData[index].condition.cname == ''){
          this.conditionList_value = ''
        }else {
          this.conditionList_value = this.tableData[index].condition.cname;//成色
        }
        if(this.tableData[index].paggregatedRock.paggregated_rock_name == ''){
          this.paggregatedRockList_value = '';//石料
        }else {
          this.paggregatedRockList_value = this.tableData[index].paggregatedRock.paggregated_rock_name;//石料
        }
        if(this.tableData[index].property.pname == ''){
          this.propertyList_value = '';//属性
        }else {
          this.propertyList_value = this.tableData[index].property.pname;//属性
        }
        if( this.tableData[index].style.sname == ''){
          this.styleList_value = '';//款式
        }else {
          this.styleList_value = this.tableData[index].style.sname;//款式
        }
        if(this.tableData[index].ppush_money_one.pmname ==''){
          this.pushMoneyList_value = '';//分类提成
        }else {
          this.pushMoneyList_value = this.tableData[index].ppush_money_one.pmname;//分类提成
        }
        if(this.tableData[index].goldContent.gcname==''){
          this.goldContentList_value = '';//含金量
        }else {
          this.goldContentList_value = this.tableData[index].goldContent.gcname;//含金量
        }
        if(this.tableData[index].productClassify.pccategory_one == ''){
          this.productClassifyList_value = '';//商品分类
        }else {
          this.productClassifyList_value = this.tableData[index].productClassify.pccategory_one;//商品分类
        }
        if(this.tableData[index].weightUnit.wuname ==''){
          this.weightUnitList_value = '';//重量单位
        }else {
          this.weightUnitList_value = this.tableData[index].weightUnit.wuname;//重量单位
        }
        if(this.tableData[index].productSet.psname == ''){
          this.productSetList_value = '';//系列
        }else {
          this.productSetList_value = this.tableData[index].productSet.psname;//系列
        }

        this.detailsData=this.tableData[index];
      },
      // 这是删除
      // handleDelete(index, row) {
      //   console.log(index, row);
      //   // this.tableData.splice(index,1);
      //   this.$axios.post("http://172.16.6.73:8080/product/fakeDeleteProduct.action").then(
      //     (res)=>{
      //   })
      // },
      handleDelete(index, row){
        console.log(index, row);
        console.log(this.tableData[index].pid);
        let data={
          id:this.tableData[index].pid
        };
        console.log(data);
        this.$axios.post("http://172.16.6.73:8080/product/fakeDeleteProduct.action",data , {
            transformRequest: [
              function (data) {
                let params = "";
                var arr = [];
                for (var key in data) {
                  arr.push(key + "=" + data[key]);
                }
                params = arr.join("&");
                return params;
              }
            ]
          },
          {
            headers: {
              'Content-Type': 'application/x-www-form-urlencoded'
            }
          }).then((res) => {
          console.log(res);
          this.getData();
        });
      },
      // 这是修改
      edit(){
        let id = this.detailsData.pid;
        let ptid,sid,cid,paggregated_rock_id,pid,sid2,pmid,pcid,psid,wuid,gcid;
        for (let i=0;i<this.tableData.length;i++){
          if(this.tableData[i].pid===id){
            this.tableData[i]=this.detailsData;
            //商品类型
            for (let i = 0;i<this.totalList.productTypeList.length;i++){
              if(this.totalList.productTypeList[i].ptname ===this.productTypeList_value){
                ptid =this.totalList.productTypeList[i].ptid;
                this.detailsData.productType = this.totalList.productTypeList[i];
                break;
              }
            }
            //供应商
            for (let i = 0;i<this.totalList.supplierList.length;i++){
              if(this.totalList.supplierList[i].sname ===this.supplierList_value){
                sid =this.totalList.supplierList[i].sid;
                this.detailsData.supplier = this.totalList.supplierList[i];
                break;
              }
            }
            //成色
            for (let i = 0;i<this.totalList.conditionList.length;i++){
              if(this.totalList.conditionList[i].cname ===this.conditionList_value){
                cid =this.totalList.conditionList[i].cid;
                this.detailsData.condition = this.totalList.conditionList[i];
                break;
              }
            }
            // 石料
            for (let i = 0;i<this.totalList.paggregatedRockList.length;i++){
              if(this.totalList.paggregatedRockList[i].paggregated_rock_name ===this.paggregatedRockList_value){
                paggregated_rock_id =this.totalList.paggregatedRockList[i].paggregated_rock_id;
                this.detailsData.paggregatedRock = this.totalList.paggregatedRockList[i];
                break;
              }
            }
            // 属性
            for (let i = 0;i<this.totalList.propertyList.length;i++){
              if(this.totalList.propertyList[i].pname ===this.propertyList_value){
                pid =this.totalList.propertyList[i].pid;
                this.detailsData.property = this.totalList.propertyList[i];
                break;
              }
            }
            //款式
            for (let i = 0;i<this.totalList.styleList.length;i++){
              if(this.totalList.styleList[i].sname ===this.styleList_value){
                sid2 =this.totalList.styleList[i].sid;
                this.detailsData.style = this.totalList.styleList[i];
                break;
              }
            }
            // 分类
            for (let i = 0;i<this.totalList.pushMoneyList.length;i++){
              if(this.totalList.pushMoneyList[i].pmname ===this.pushMoneyList_value){
                pmid =this.totalList.pushMoneyList[i].pmid;
                this.detailsData.ppush_money1 = this.totalList.pushMoneyList[i];
                this.detailsData.ppush_money2 = this.totalList.pushMoneyList[i];
                break;
              }
            }
            //商品分类
            for (let i = 0;i<this.totalList.productClassifyList.length;i++){
              if(this.totalList.productClassifyList[i].pccategory_one ===this.productClassifyList_value){
                pcid =this.totalList.productClassifyList[i].pcid;
                this.detailsData.productClassify = this.totalList.productClassifyList[i];
                // this.addData.productClassify = pcid;
                break;
              }
            }
            // 系列
            for (let i = 0;i<this.totalList.productSetList.length;i++){
              if(this.totalList.productSetList[i].psname ===this.productSetList_value){
                psid =this.totalList.productSetList[i].psid;
                this.detailsData.productSet = this.totalList.productSetList[i];
                // this.addData.productSet = psid;
                break;
              }
            }
            // 重量单位
            for (let i = 0;i<this.totalList.weightUnitList.length;i++){
              if(this.totalList.weightUnitList[i].wuname ===this.weightUnitList_value){
                wuid =this.totalList.weightUnitList[i].wuid;
                this.detailsData.weightUnit = this.totalList.weightUnitList[i];
                // this.addData.weightUnit = wuid;
                break;
              }
            }
            //含金量
            for (let i = 0;i<this.totalList.goldContentList.length;i++){
              if(this.totalList.goldContentList[i].gcname ===this.goldContentList_value){
                gcid =this.totalList.goldContentList[i].gcid;
                this.detailsData.goldContent = this.totalList.goldContentList[i];
                // this.addData.goldContent = gcid;
                break;
              }
            }
          }
        }
        console.log(this.detailsData);
        let data={
          pid:id,//pid
          pproduct_type_ptid:this.detailsData.productType.ptid,//商品类型
          pcode:this.detailsData.pcode,//商品编码
          pname:this.detailsData.pname,//商品名称
          pmould_no:this.detailsData.pmould_no,//模具号
          psupplier_sid:this.detailsData.supplier.sid,//供应商
          psection_number:this.detailsData.psection_number,//款号
          pecommerce_fund_no:this.detailsData.pecommerce_fund_no,//电商款号
          product_product_classify_pcid:this.detailsData.productClassify.pcid,//商品分类
          prodcut_gold_content_gcid:this.detailsData.goldContent.gcid,//含金量
          pcondition_cid:this.detailsData.condition.cid,//成色
          paggregated_rock_prid:this.detailsData.paggregatedRock.paggregated_rock_id,//石料
          pproperty_pid:this.detailsData.property.pid,//属性
          pstyle_sid:this.detailsData.style.sid,//款式
          pconsult_weight:this.detailsData.pconsult_weight,//参考重量
          product_weight_unit:this.detailsData.weightUnit.wuid,//重量单位
          product_hand:this.detailsData.product_hand,//手寸
          pprime_cost_valuation:this.detailsData.pprime_cost_valuation,//成本计价
          pprime_cost_price:this.detailsData.pprime_cost_price,//成本价
          pmarket_house_price:this.detailsData.pmarket_house_price,//市场价
          psell_valuation:this.weightUnitList_value,//销售计价
          plabel_price:this.detailsData.plabel_price,//标签单价
          psales_cost:this.detailsData.psales_cost,//销售工费
          psell_extra_charge:this.detailsData.psell_extra_charge,//销售附加费
          pstock_count:this.radio,//是否纳入库存
          ppush_money:this.detailsData.ppush_money,//提成分类
          ppush_money1:this.detailsData.ppush_money1.pmid,//提成分类
          ppush_money2:this.detailsData.ppush_money2.pmid,//提成分类
          product_product_set_psid:this.detailsData.productSet.psid,//系列
        };
        // console.log(data);
        this.$axios.post("http://172.16.6.73:8080/product/updateProduct.action",data , {
            transformRequest: [
              function (data) {
                let params = "";
                var arr = [];
                for (var key in data) {
                  arr.push(key + "=" + data[key]);
                }
                params = arr.join("&");
                return params;
              }
            ]
          },
          {
            headers: {
              'Content-Type': 'application/x-www-form-urlencoded'
            }
          }).then((res) => {
          console.log("修改成功");
          // this.getData();
        });
        this.getData();
      },
      //这是新增
      add(){
        // var newObj = this.tableData[0].clone(true);
        let ptid,sid,cid,paggregated_rock_id,pid,sid2,pmid,pcid,psid,wuid,gcid;
        // this.addData.id=id;
        //商品类型
        for (let i = 0;i<this.totalList.productTypeList.length;i++){
          if(this.totalList.productTypeList[i].ptname ===this.productTypeList_value){
            ptid =this.totalList.productTypeList[i].ptid;
            this.addData.productType = this.totalList.productTypeList[i];
            // this.addData.productType = ptid;
            break;
          }
        }
        //供应商
        for (let i = 0;i<this.totalList.supplierList.length;i++){
          if(this.totalList.supplierList[i].sname ===this.supplierList_value){
            sid =this.totalList.supplierList[i].sid;
            this.addData.supplier = this.totalList.supplierList[i];
            // this.addData.supplier = sid;
            break;
          }
        }
        //成色
        for (let i = 0;i<this.totalList.conditionList.length;i++){
          if(this.totalList.conditionList[i].cname ===this.conditionList_value){
            cid =this.totalList.conditionList[i].cid;
            this.addData.condition = this.totalList.conditionList[i];
            // this.addData.condition = cid;
            break;
          }
        }
        // 石料
        for (let i = 0;i<this.totalList.paggregatedRockList.length;i++){
          if(this.totalList.paggregatedRockList[i].paggregated_rock_name ===this.paggregatedRockList_value){
            paggregated_rock_id =this.totalList.paggregatedRockList[i].paggregated_rock_id;
            this.addData.paggregatedRock = this.totalList.paggregatedRockList[i];
            // console.log(5555)
            // this.addData.paggregatedRock = paggregated_rock_id;
            break;
          }
        }
        // 属性
        for (let i = 0;i<this.totalList.propertyList.length;i++){
          if(this.totalList.propertyList[i].pname ===this.propertyList_value){
            pid =this.totalList.propertyList[i].pid;
            this.addData.property = this.totalList.propertyList[i];
            // this.addData.property = pid;
            break;
          }
        }
        //款式
        for (let i = 0;i<this.totalList.styleList.length;i++){
          if(this.totalList.styleList[i].sname ===this.styleList_value){
            sid2 =this.totalList.styleList[i].sid;
            this.addData.style = this.totalList.styleList[i];
            // this.addData.style = sid2;
            break;
          }
        }
        // 分类
        for (let i = 0;i<this.totalList.pushMoneyList.length;i++){
          if(this.totalList.pushMoneyList[i].pmname ===this.pushMoneyList_value){
            pmid =this.totalList.pushMoneyList[i].pmid;
            this.addData.ppush_money1 = this.totalList.pushMoneyList[i];
            this.addData.ppush_money2 = this.totalList.pushMoneyList[i];
            // this.addData.ppush_money1 = pmid;
            // this.addData.ppush_money2 = pmid;
            break;
          }
        }
        //商品分类
        for (let i = 0;i<this.totalList.productClassifyList.length;i++){
          if(this.totalList.productClassifyList[i].pccategory_one ===this.productClassifyList_value){
            pcid =this.totalList.productClassifyList[i].pcid;
            this.addData.productClassify = this.totalList.productClassifyList[i];
            // this.addData.productClassify = pcid;
            break;
          }
        }
        // 系列
        for (let i = 0;i<this.totalList.productSetList.length;i++){
          if(this.totalList.productSetList[i].psname ===this.productSetList_value){
            psid =this.totalList.productSetList[i].psid;
            this.addData.productSet = this.totalList.productSetList[i];
            // this.addData.productSet = psid;
            break;
          }
        }
        // 重量单位
        for (let i = 0;i<this.totalList.weightUnitList.length;i++){
          if(this.totalList.weightUnitList[i].wuname ===this.weightUnitList_value){
            wuid =this.totalList.weightUnitList[i].wuid;
            this.addData.weightUnit = this.totalList.weightUnitList[i];
            // this.addData.weightUnit = wuid;
            break;
          }
        }
        //含金量
        for (let i = 0;i<this.totalList.goldContentList.length;i++){
          if(this.totalList.goldContentList[i].gcname ===this.goldContentList_value){
            gcid =this.totalList.goldContentList[i].gcid;
            this.addData.goldContent = this.totalList.goldContentList[i];
            // this.addData.goldContent = gcid;
            break;
          }
        }
        let productType={
          ptid:this.addData.productType.ptid
        }
        let data={

          // productType:{
          //   ptid:this.addData.productType,
          // }, //商品类型
          // pcode:this.addData.pcode,//商品编码
          // pname:this.addData.pname,//商品名称
          // pmould_no:this.addData.pmould_no,//模具号
          // supplier:{
          //   sid:this.addData.supplier
          // },//供应商
          // psection_number:this.addData.psection_number,//款号
          // pecommerce_fund_no:this.addData.pecommerce_fund_no,//电商款号
          // productClassify:{
          //   pcid:this.addData.productClassify
          // },//商品分类
          // goldContent:{
          //   gcid: this.addData.goldContent,
          // },//含金量
          // condition:{
          //   cid:this.addData.condition
          // },//成色
          // paggregatedRock:{
          //   prid:this.addData.paggregatedRock,
          // },//石料
          // property:{
          //   pid:this.addData.property
          // },//属性
          // style:{
          //   sid:this.addData.style
          // },//款式
          // pconsult_weight:this.addData.pconsult_weight,//参考重量
          // weightUnit:{
          //   wuid:this.addData.weightUnit,
          // },//重量单位
          // product_hand:this.addData.product_hand,//手寸
          // pprime_cost_valuation:this.weightList.value,//成本计价
          // pprime_cost_price:this.addData.pprime_cost_price,//成本价
          // pmarket_house_price:this.addData.pmarket_house_price,//市场价
          // psell_valuation:this.weightList.value,//销售计价
          // plabel_price:this.addData.plabel_price,//标签单价
          // psales_cost:this.addData.psales_cost,//销售工费
          // psell_extra_charge:this.addData.psell_extra_charge,//销售附加费
          // pstock_count:this.radio,//是否纳入库存
          // ppush_money:this.addData.ppush_money,//提成分类
          // ppush_money_one:{
          //   pmid:this.addData.ppush_money1
          // },//提成分类
          // ppush_money_two:{
          //   pmid:this.addData.ppush_money2
          // },//提成分类
          // productSetList:{
          //   psid:this.addData.productSet,
          // },//系列
          pproduct_type_ptid:this.addData.productType.ptid,//商品类型
          pcode:this.addData.pcode,//商品编码
          pname:this.addData.pname,//商品名称
          pmould_no:this.addData.pmould_no,//模具号
          psupplier_sid:this.addData.supplier.sid,//供应商
          psection_number:this.addData.psection_number,//款号
          pecommerce_fund_no:this.addData.pecommerce_fund_no,//电商款号
          product_product_classify_pcid:this.addData.productClassify.pcid,//商品分类
          prodcut_gold_content_gcid:this.addData.goldContent.gcid,//含金量
          pcondition_cid:this.addData.condition.cid,//成色
          paggregated_rock_prid:this.addData.paggregatedRock.paggregated_rock_id,//石料
          pproperty_pid:this.addData.property.pid,//属性
          pstyle_sid:this.addData.style.sid,//款式
          pconsult_weight:this.addData.pconsult_weight,//参考重量
          product_weight_unit:this.addData.weightUnit.wuid,//重量单位
          product_hand:this.addData.product_hand,//手寸
          pprime_cost_valuation:this.addData.pprime_cost_valuation,//成本计价
          pprime_cost_price:this.addData.pprime_cost_price,//成本价
          pmarket_house_price:this.addData.pmarket_house_price,//市场价
          psell_valuation:this.weightUnitList_value,//销售计价
          plabel_price:this.addData.plabel_price,//标签单价
          psales_cost:this.addData.psales_cost,//销售工费
          psell_extra_charge:this.addData.psell_extra_charge,//销售附加费
          pstock_count:this.radio,//是否纳入库存
          ppush_money:this.addData.ppush_money,//提成分类
          ppush_moneyone:this.addData.ppush_money1.pmid,//提成分类
          ppush_moneytwo:this.addData.ppush_money2.pmid,//提成分类
          product_product_set_psid:this.addData.productSet.psid,//系列
        };
        console.log(data);
        // let mydata = JSON.stringify(data);

        this.$axios.post("http://172.16.6.73:8080/product/addProduct.action",data , {
            transformRequest: [
              function (data) {
                let params = "";
                var arr = [];
                for (var key in data) {
                  arr.push(key + "=" + data[key]);
                }
                params = arr.join("&");
                return params;
              }
            ]
          },
          {
            headers: {
              'Content-Type': 'application/x-www-form-urlencoded'
            }
          }).then((res) => {
          console.log("添加成功");
          // this.getData();
        });
        console.log("0添加操作");
        console.log(this.addData);
        // this.tableData.push(this.addData);
      },
      //关键字搜索
      tables:function (keyword) {
        return this.tableData.filter(function (item) {
          if (item.pcode.includes(keyword)){
            return item;
          }
        })
      },
    }
  }
</script>
<style scoped>
  .content{
    width: 80%;
    background-color: white;
  }
  .input{
    width: 200px;
  }
  .Product_coding_table,
  .details_table
  {
    width: 100%;
    text-align: right;
  }
  .Product_coding_table td,
  .details_table td{
    width: 100px;
  }
  .Product_coding_table tr,
  .details_table tr{
    height: 30px;
  }
  .Product_coding_table input,
  .details_table input{
    width: 100%;
  }
</style>
